rm(list = ls())

install.packages("maps")
install.packages("mapproj")
install.packages("ggthemes")
install.packages("data.table")
install.packages("epiDisplay")
install.packages("dplyr")
install.packages("cowplot")
install.packages("tibble")
devtools::install_github("hrbrmstr/ggalt")
install.packages("lubridate")
install.packages("ggrepel")


library(ggplot2)
library(maptools)
library(rworldmap)
library(tidyverse)
library(maps)
library(countrycode)
library(readxl)
library(reshape2)
library(maps)
library(mapproj)
library(ggthemes)
library(data.table)
library(epiDisplay)
library(dplyr)
library(cowplot)
library(ggalt)
library(tibble)
library(lubridate)
library(grid)


#----------------------------------------------------------------------------------#
# Set working directory
setwd("/Users/kelebogilezvobgo/Dropbox/1_Research/1_Publications/12_Democratizing-Truth/ijab029_replication_files")

# Load the data
tc <- read.csv("VTC_United States pz2021democratizing.csv")
#----------------------------------------------------------------------------------#


# Prep the data
tc$subnational <- as.factor(tc$subnational)
tc$subnationaltotal_bystate <- as.factor(tc$subnationaltotal_bystate)
tc$state_level_total <- as.factor(tc$state_level_total)
us_states <- map_data("state")
tc$region <- tolower(tc$state_name)
us_states_tc <- left_join(us_states, tc)





########################################################
## Subnational U.S. Truth Commissions by State (All) ##
########################################################

p2 <- ggplot(data=us_states_tc,
             mapping = aes(x = long, y = lat,
                           group = group, fill = subnational)) + 
  geom_polygon(color = "black", size = 0.1) + 
  coord_map(projection = "albers", lat0 = 39, lat1 = 45) +  
  scale_fill_manual("TCs", values = c("#6baed6","#08519c"), na.value="white", labels = c("1", "0")) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(),
        axis.title.y=element_blank(), axis.text.y=element_blank(),axis.ticks.y=element_blank()) +
  theme(legend.key.size = unit(2, "lines")) +
  theme(legend.title = element_text(size = 18), legend.text = element_text(size = 16))+
  theme(panel.background = element_rect(fill = "gray90")) +
  theme(plot.margin = margin(-2, 0, -2, -2, "cm")) + #bottom, left, top, right 
  theme(legend.position = "right")

p2

## Save the figure
#ggsave('Subnational U.S. Truth Commissions (All).jpg', dpi=300, width = 12, height = 6)





####################################################################
## Subnational U.S. Truth Commissions by State (State Level Only) ##
####################################################################

p3 <- ggplot(data=us_states_tc,
             mapping = aes(x = long, y = lat,
                           group = group, fill = state_level_total)) + 
  geom_polygon(color = "black", size = 0.1) + 
  coord_map(projection = "albers", lat0 = 39, lat1 = 45) +  
  scale_fill_manual("TCs", values = c("#08519c","#3182bd"), na.value="white", labels = c("1", "0")) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(),
        axis.title.y=element_blank(), axis.text.y=element_blank(),axis.ticks.y=element_blank()) +
  theme(legend.key.size = unit(2, "lines")) +
  theme(legend.title = element_text(size = 18), legend.text = element_text(size = 16))+
  theme(panel.background = element_rect(fill = "gray90")) +
  theme(plot.margin = margin(-2, 0, -2, -2, "cm")) + #bottom, left, top, right 
  theme(legend.position = "right")
p3

## Save the figure
#ggsave('Subnational U.S. Truth Commissions (State Level Only).jpg', dpi=300, width = 12, height = 6)